#include "stdafx.h"
#include <CppUnitTest.h>

#include "nef.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

using namespace nef;

class IxA
{
public:
	virtual ~IxA() {}

	virtual int Val() const = 0;
};

class IxB
{
public:
	virtual ~IxB() {}

	virtual int Val() const = 0;
};

class Impl
	: public virtual IxA, public virtual IxB
{
public:
	Impl()
		: Ct(COUNTER++)
	{

	}

	virtual int Val() const
	{
		return Ct;
	}

	int Ct;

	static int COUNTER;
};

nef_export<Impl, IxA> ixa_export;
nef_export<Impl, IxB> ixb_export;

int Impl::COUNTER = 0;

namespace nef_unit_test
{		
	TEST_CLASS(shared_export_tests)
	{
	public:
		
		TEST_METHOD(VerifySameInstance)
		{
			auto cat = Catalog::Create();

			auto a = cat->GetExportedValue<IxA>(NO_CONTRACT, false);
			auto b = cat->GetExportedValue<IxB>(NO_CONTRACT, false);

			Assert::IsNotNull(a.get(), L"Could not locate interface IxA", LINE_INFO());
			Assert::IsNotNull(b.get(), L"Could not locate interface IxB", LINE_INFO());

			Assert::AreEqual(a->Val(), b->Val(), L"The specified interfaces do not share the same implementation", LINE_INFO());
		}

	};
}